package ru.inse.realty.web.page;

import javax.servlet.http.HttpServletRequest;

import ru.inse.realty.core.dao.RealtyQueryParam;
import ru.inse.realty.core.domain.RealtyObject;
import ru.inse.realty.core.domain.RealtyObjectType;
import ru.inse.realty.core.domain.RealtyRubric;
import ru.inse.web.module.InseUrlParamBuilder;

/**
 * Класс для построения параметров URL 
 * @author evga
 */
public class RealtyUrlParamBuilder
    extends InseUrlParamBuilder<RealtyQueryParam>
{
    
    public static final String LO_PRICE = "loPrice";
    public static final String HI_PRICE = "hiPrice";
    public static final String LO_AREA = "loArea";
    public static final String HI_AREA = "hiArea";
    public static final String LO_I1 = "loI1";
    public static final String HI_I1 = "hiI1";
    public static final String LO_I2 = "loI2";
    public static final String HI_I2 = "hiI2";
    public static final String STREET_NAME = "streetName";
    
    public RealtyUrlParamBuilder(final RealtyQueryParam realtyQueryParam)
    {
        super(realtyQueryParam);
    }


    @Override
    protected void addAdvancedParam(StringBuilder sb)
    {
        super.addAdvancedParam(sb);
        RealtyQueryParam param = getQueryParam();
        add(LO_PRICE, param.getLoPrice(), sb);
        add(HI_PRICE, param.getHiPrice(), sb);
        add(LO_AREA, param.getLoArea(), sb);
        add(HI_AREA, param.getHiArea(), sb);
        add(LO_I1, param.getLoI1(), sb);
        add(HI_I1, param.getHiI1(), sb);
        add(LO_I2, param.getLoI2(), sb);
        add(HI_I2, param.getHiI2(), sb);
        add(STREET_NAME, param.getPlaceName(), sb);
    }
    
    static public String buildUrl(RealtyQueryParam param, RealtyRubric rubric, RealtyObjectType type, RealtyObject object)
    {
        StringBuilder sb = new StringBuilder();
        if (rubric == null)
        {
            rubric = type.getDefaultRubric();
        }
        sb.append(String.format("", param.getCityId(), rubric.getCode(), object.getId()));
        return sb.toString();
    }
}
